package com.fone.player.online.adapter;

import java.util.List;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.fone.player.R;
import com.fone.player.cache.ImageDownloadModule;
import com.fone.player.entity.EveryoneItemInfo;

/**
 * 大家都在看的条目adapter
 * 
 * @author JasonZue
 * @since 2014-5-9
 */

public class EveryOneListAdapter extends BaseAdapter {

	private Context mContext;
	private List<EveryoneItemInfo> everyoneData;

	public EveryOneListAdapter(Context mContext,
			List<EveryoneItemInfo> everyoneData) {
		this.mContext = mContext;
		this.everyoneData = everyoneData;
	}

	@Override
	public int getCount() {
		return everyoneData.size();

	}

	@Override
	public Object getItem(int position) {
		return everyoneData.get(position);

	}

	@Override
	public long getItemId(int position) {
		return position;

	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = View.inflate(mContext, R.layout.item_everyone, null);
			holder.userName = (TextView) convertView
					.findViewById(R.id.everyone_item_username_tv);
			holder.videoName = (TextView) convertView
					.findViewById(R.id.everyone_item_video_name_tv);
			holder.videoSource = (TextView) convertView
					.findViewById(R.id.everyone_item_video_source_tv);
			holder.videoImage = (ImageView) convertView
					.findViewById(R.id.everyone_item_video_image_iv);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		if(TextUtils.isEmpty(everyoneData.get(position).getUserName())){
			holder.userName.setText("游客正在看");
		}else {
			holder.userName.setText(everyoneData.get(position).getUserName()+"正在看");
		}
		holder.videoName.setText(everyoneData.get(position).getItemName());
		ImageDownloadModule.getInstance().download(
				everyoneData.get(position).getImageUrl(), R.drawable.default_340_192, holder.videoImage);
		if(TextUtils.isEmpty(everyoneData.get(position).getItemContent())){
			holder.videoSource.setText("来源:未知");
		}else {
			holder.videoSource.setText("来源:"+everyoneData.get(position).getItemContent());
		}

		return convertView;

	}

	static class ViewHolder {
		private TextView userName, videoName, videoSource;// 用户名,视频名称,视频来源
		private ImageView videoImage;// 视频图片
	}

}
